package com.klhappy.houyuan.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.AllGoodsRecord;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.activity.XiangqingActivity;
import com.klhappy.houyuan.view.ImageManager;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by MrPu on 15/12/4.
 */
public class GoodsClassAdapter extends BaseAdapter {
    private List<AllGoodsRecord.Record> list;
    private Context context;

    public GoodsClassAdapter(List<AllGoodsRecord.Record> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(
                    R.layout.gridview_item, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        ImageManager.loadImage(UrlConstant.BASE_URL + list.get(position).getG_icon() ,viewHolder.ivPhoto);
        viewHolder.tvName.setText(list.get(position).getG_name());
        viewHolder.tvPrice.setText("￥ " + list.get(position).getG_price());
        viewHolder.tvCount.setText(list.get(position).getSaleNo() + "人已付款");
        viewHolder.ivPhoto.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context ,XiangqingActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("goodId" ,list.get(position).getG_id() + "");
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        return view;
    }
    static class ViewHolder {
        @InjectView(R.id.ivPhoto)
        ImageView ivPhoto;
        @InjectView(R.id.tvName)
        TextView tvName;
        @InjectView(R.id.tvPrice) TextView tvPrice;
        @InjectView(R.id.tvCount) TextView tvCount;
        @InjectView(R.id.chose_li)
        LinearLayout chose_li;
        @InjectView(R.id.click_re)
        RelativeLayout click_re;
        private boolean flag = true;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
